package org.ala.tiktools.sharddb.db.config;


import org.ala.tiktools.sharddb.Namespace;
import org.springframework.beans.PropertyValues;

/**
 * 分库配置信息
 * <p>  读取 datasource.xxx.信息，格式（有初值的地方是默认值，可以不配。特殊的，key为default时，表示找不到数据源时的默认数据源）：
 * datasource:
 *    xxx:
 *       mapperLocations:
 *       type: "druid"       #   连接池类型
 *       driverClassName:
 *       url:
 *       username:
 *       password:
 *       pool:                  #   连接池配置
 *          initialSize: 2
 *          minIdle: 5
 *          maxWait: 10
 *          maxWait: 6000
 *          timeBetweenEevictionRunsMillis: 6000
 *          minEvictableIdleTimeMillis: 6000
 *          validationQuery: "select 1"
 *          testWhileIdle: true
 *          testOnBorrow: true
 *          testOnReturn: false
 *          poolPreparedStatements: false
 *          maxPoolPreparedStatementPerConnectionSize: 2
 *
 *
 *
 * @author ala
 * @date 2024-12-27 10:35
 */
public class ShardDataSourceConfigInfo {

    /**
     *  数据源key
     */
    protected String key;

    /**
     *  数据源基本配置
     */
    protected String type;
    protected String mapperLocations;
    protected String driverClassName;
    protected String url;
    protected String username;
    protected String password;
    protected PoolConfig pool;
    protected DiversionConfig diversion;


    /**
     *  分流池配置
     */
    public static class DiversionConfig {
        protected boolean enabled;
        protected int size;

        public boolean isEnabled() {
            return enabled;
        }

        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }

        public int getSize() {
            return size;
        }

        public void setSize(int size) {
            this.size = size;
        }
    }
    /**
     *  连接池配置
     */
    public static class PoolConfig {
        protected Integer initialSize = 2;
        protected Integer minIdle = 5;
        protected Integer maxActive = 10;
        protected Long maxWait = 60000l;
        protected Long timeBetweenEevictionRunsMillis = 60000l;
        protected Long minEvictableIdleTimeMillis = 30000l;
        protected String validationQuery = "select 1";
        protected Boolean testWhileIdle = true;
        protected Boolean testOnBorrow = true;
        protected Boolean testOnReturn = false;
        //	是否缓存preparedStatement，也就是PSCache  官方建议MySQL下建议关闭   个人建议如果想用SQL防火墙 建议打开
        protected Boolean poolPreparedStatements = false;
        protected Integer maxPoolPreparedStatementPerConnectionSize = 20;

        public Integer getInitialSize() {
            return initialSize;
        }

        public void setInitialSize(Integer initialSize) {
            this.initialSize = initialSize;
        }

        public Integer getMinIdle() {
            return minIdle;
        }

        public void setMinIdle(Integer minIdle) {
            this.minIdle = minIdle;
        }

        public Integer getMaxActive() {
            return maxActive;
        }

        public void setMaxActive(Integer maxActive) {
            this.maxActive = maxActive;
        }

        public Long getMaxWait() {
            return maxWait;
        }

        public void setMaxWait(Long maxWait) {
            this.maxWait = maxWait;
        }

        public Long getTimeBetweenEevictionRunsMillis() {
            return timeBetweenEevictionRunsMillis;
        }

        public void setTimeBetweenEevictionRunsMillis(Long timeBetweenEevictionRunsMillis) {
            this.timeBetweenEevictionRunsMillis = timeBetweenEevictionRunsMillis;
        }

        public Long getMinEvictableIdleTimeMillis() {
            return minEvictableIdleTimeMillis;
        }

        public void setMinEvictableIdleTimeMillis(Long minEvictableIdleTimeMillis) {
            this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
        }

        public String getValidationQuery() {
            return validationQuery;
        }

        public void setValidationQuery(String validationQuery) {
            this.validationQuery = validationQuery;
        }

        public Boolean getTestWhileIdle() {
            return testWhileIdle;
        }

        public void setTestWhileIdle(Boolean testWhileIdle) {
            this.testWhileIdle = testWhileIdle;
        }

        public Boolean getTestOnBorrow() {
            return testOnBorrow;
        }

        public void setTestOnBorrow(Boolean testOnBorrow) {
            this.testOnBorrow = testOnBorrow;
        }

        public Boolean getTestOnReturn() {
            return testOnReturn;
        }

        public void setTestOnReturn(Boolean testOnReturn) {
            this.testOnReturn = testOnReturn;
        }

        public Boolean getPoolPreparedStatements() {
            return poolPreparedStatements;
        }

        public void setPoolPreparedStatements(Boolean poolPreparedStatements) {
            this.poolPreparedStatements = poolPreparedStatements;
        }

        public Integer getMaxPoolPreparedStatementPerConnectionSize() {
            return maxPoolPreparedStatementPerConnectionSize;
        }

        public void setMaxPoolPreparedStatementPerConnectionSize(Integer maxPoolPreparedStatementPerConnectionSize) {
            this.maxPoolPreparedStatementPerConnectionSize = maxPoolPreparedStatementPerConnectionSize;
        }
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getMapperLocations() {
        return mapperLocations;
    }

    public void setMapperLocations(String mapperLocations) {
        this.mapperLocations = mapperLocations;
    }

    public String getDriverClassName() {
        return driverClassName;
    }

    public void setDriverClassName(String driverClassName) {
        this.driverClassName = driverClassName;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public PoolConfig getPool() {
        return pool;
    }

    public void setPool(PoolConfig pool) {
        this.pool = pool;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public DiversionConfig getDiversion() {
        return diversion;
    }

    public void setDiversion(DiversionConfig diversion) {
        this.diversion = diversion;
    }
}
